package com.ebupt.migu.music.userlist.service;

import cn.hutool.json.JSONUtil;
import com.ebupt.migu.music.api.util.CacheTask;
import com.ebupt.migu.music.common.constants.RedidKeyConstant;
import com.ebupt.migu.music.roster.entity.RosterBlackEntity;
import com.ebupt.migu.music.roster.mapper.RosterMapper;
import com.ebupt.migu.music.userlist.entity.UserBlackList;
import com.ebupt.migu.music.userlist.mapper.BlackListMapper;
import com.ebupt.migu.music.common.entity.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 *
 * @author lizm
 */
@Service
public class BlackListService {
    @Autowired
    private BlackListMapper blMapper;
    @Resource
    protected RedisTemplate redisTemplate;

    public Integer addBlackList(Map<String, Object> paramMap) {
        try {
            blMapper.addBlackList(paramMap);
            return (Integer) paramMap.get("id");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public Integer delBlackList(Map<String, Object> paramMap) {
                try {
                    Integer total = blMapper.delBlackList(paramMap);
                    return total;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
    }
    /**
     * 分页查询黑名单
     * @param paramMap
     * @return
     */
    public Page<UserBlackList> queryByPage(Map<String,Object> paramMap){
        //current:1,当前页码every:10,每页条数
        Page<UserBlackList> page = new Page<>();
        List<UserBlackList> list = blMapper.queryByPage(paramMap);
        Integer total = blMapper.queryCount(paramMap);
        page.setTotal(total);
        page.setData(list);
        return page;
    }

    public Integer delBlackListBatch(Map<String, Object> paramMap) {
        {
            try {
                String idsStr= (String) paramMap.get("ids");
                String[] ids=idsStr.split(",");
                paramMap.put("idsArr",ids);
                Integer integer = blMapper.delBlackListBatch(paramMap);
                return integer;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public List<UserBlackList> checkBlackList(Map<String, Object> paramMap) {
        List<UserBlackList> list = blMapper.checkBlackList(paramMap);
        return list;
    }



}
